package 力扣日常刷题.木22一月.第12天0120;

/**
 * @author 帅小伙
 * @date 2022/1/20
 * @description
 */
public class Demo33动态规划中等打家劫舍 {


    public int rob(int[] nums) {
        int n = nums.length;
        if(n == 1)return nums[0];

        int first = nums[0] ,second = Math.max(nums[0],nums[1]);

        for (int i = 2; i < n; i++) {
            int t = second;
            second  = Math.max(first+nums[i],second);
            first = t;
        }
        return second;
    }
}
